﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace WcfAfvandingServiceLibrary
{
    [Serializable]
    public class Kanal
    {
        private const string connectionString = "Data Source=ealdb1.eal.local;User ID=ejl02_usr;Password=Baz1nga2;Initial Catalog=EJL02_DB;Trusted_connection=False";
        SqlConnection con;
        SqlCommand cmd;
        SqlDataReader datareader;

        string kanalNavn;
        double vandstand;
        int kanalId;

        public string KanalNavn
        {
            get { return kanalNavn; }
            set { kanalNavn= value; }
        }

        public double Vandstand
        {
            get 
            {
                con = new SqlConnection(connectionString);
                cmd = new SqlCommand();
                cmd.Connection = con;
                cmd.CommandText = "SELECT vandstand FROM Kanal";
                con.Open();
                datareader = cmd.ExecuteReader();

                datareader.Read();
                vandstand = (double)datareader["vandstand"];
                con.Close();
                return vandstand; 
            }
            set 
            {
                cmd.Connection = con;
                datareader = null;
                cmd.CommandText = "UPDATE Kanal SET vandstand = " + vandstand;
                cmd.Parameters.Clear();

                SqlParameter par = new SqlParameter("vandstand", SqlDbType.Float);
                par.Value = vandstand;
                cmd.Parameters.Add(par);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

                vandstand = value; 
            }
        }

        public int KanalId
        {
            get { return kanalId; }
            set { kanalId = value; }
        }
    }
}